#include <stdio.h>
#include "heap.h"

void outputRoadOfHeap(struct MinHeap* h,int i){
	while( i!=0 ){
		printf(i==1? "%d":"%d ", h->element[i]);
		i/=2;
	}
	printf("\n");
}
int main(){ 
	freopen("in.txt","r",stdin);
	int m,n;
	scanf("%d %d",&n,&m);
	struct MinHeap* h = createMinHeap(n);
	for( int i=0; i<n; i++){
		int a;
		scanf("%d",&a);
		insert(h,a);
	}
	for( int i=0; i<m; i++ ){
		int a;
		scanf("%d",&a);
		outputRoadOfHeap(h,a);
	}
		return 0;
}
